package 面向对象_中.a继承.练习2圆的面积;

import java.text.DecimalFormat;

/**
 * @Projectname java_based
 * @Filename CylinderTest
 * @Author an
 * @Data 2022/6/29 21:42
 * @Description TODO
 */
public class CylinderTest {
    public static void main(String[] args) {

        Cylinder cy = new Cylinder();

        cy.setRadius(2.1);
        cy.setLength(3.4);
        double volues = cy.findVolume();
        System.out.println("圆柱的体积:" + volues);


        double area = cy.findArea();
        System.out.println("圆的面积: " + area);
        System.out.println("-----------------------");

        //java保留两位小数操作
        //方法一：String.format()
        String format = String.format("%.2f", volues);
        System.out.println(format);
        //string类型转double
        Double aDouble = Double.valueOf(format);
        System.out.println(aDouble);
        //方法二：DecimalFormat
        DecimalFormat df = new DecimalFormat("#.00");
        System.out.println(df.format(volues));

    }
}
